<template>
	<view class="template-product tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<!-- 顶部自定义导航开始 -->
		<view class="tn-navbg" :style="{height: vuex_custom_bar_height + 'px'}">
			<!-- 顶部自定义导航 -->
			<tn-nav-bar fixed alpha customBack>
				<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
					<text class='icon tn-icon-left'></text>
					<text class='icon tn-icon-home-capsule-fill'></text>
				</view>
				<view class="tn-flex tn-flex-col-center tn-flex-row-center ">
					<text class="tn-text-bold tn-text-xl tn-color-black">答题结果分析</text>
				</view>
			</tn-nav-bar>
		</view>
		<!-- 顶部自定义导航结束 -->
		<view class="tn-padding-top-sm tn-padding-bottom-sm">
			<view class="tn-margin">
				<view class="tn-margin" style="margin-left: 0rpx !important;">
					<view class="tn-flex tn-flex-row-between">
						<view class="justify-content-item tn-text-bold tn-text-xl">
							试卷基础信息
						</view>
					</view>
				</view>
				<view class="tn-flex tn-flex-row-between">
					<view class="justify-content-item tn-text-bold tn-margin-top-xs" style="font-size: 38rpx;">
						{{collectionContent.title || ""}}
					</view>

				</view>
				<view class="tn-flex tn-flex-row-start tn-margin-top">
					<view class="justify-content-item tn-color-gray">
						{{collectionContent.remark || ""}}
					</view>
				</view>
				<view class="tn-flex tn-flex-row-start tn-margin-top">
					<!-- <view class="justify-content-item tn-text-bold tn-color-purplered">
					<text class="" style="font-size: 50rpx;">会员免费</text>
					<text class="tn-padding-left-xs" style="font-size: 30rpx;">￥</text>
				</view> -->
					<view class="justify-content-item tn-color-gray tn-padding-top-xs">
						<view class="">答题人数 {{collectionContent.submit || 0 }}</view>
					</view>
					<view class="justify-content-item tn-color-gray tn-padding-top-xs" style="padding-left: 10rpx;">
						<view class="">收藏人数 {{collectionContent.collect || 0 }}</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>

		<!-- 答题结果对比开始 -->
		<view class="tn-padding-top-sm tn-padding-bottom-sm">
			<view class="tn-margin">
				<view class="tn-flex tn-flex-row-between">
					<view class="justify-content-item tn-text-bold tn-text-xl">
						答题结果对比
					</view>
				</view>
			</view>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-flex-1">对比类目</view>
					<view class="tn-flex-1">试卷信息</view>
					<view class="tn-flex-1">答题信息</view>
				</view>
			</tn-list-cell>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-flex-1">试卷时间</view>
					<view class="tn-flex-1">{{collectionContent.time}}</view>
					<view class="tn-flex-1">{{submitInfo.submit.submit_time || "暂无数据"}}</view>
				</view>
			</tn-list-cell>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-flex-1">试卷分数</view>
					<view class="tn-flex-1">{{collectionContent.score}}</view>
					<view class="tn-flex-1">{{submitInfo.submit.score}}</view>
				</view>
			</tn-list-cell>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-flex-1">试卷数量</view>
					<view class="tn-flex-1">
						{{collectionContent.option_count + collectionContent.multi_count + collectionContent.jude_count }}
					</view>
					<view class="tn-flex-1" style="display: flex;">
						<view>
							正确:<text style="padding-left: 20rpx;"
								class="tn-text-df tn-color-teal">{{submitInfo.submit.correct_count}}</text>
						</view>
						<view style="margin-left: 10rpx;">
							错误:<text style="padding-left: 20rpx;"
								class="tn-text-df tn-color-red">{{submitInfo.submit.error_count}}</text>
						</view>
					</view>
				</view>
			</tn-list-cell>
		</view>
		<!-- 答题结果对比结束 -->

		<view class="tn-strip-bottom"></view>

		<!-- 信息流广告开始 -->
		<view class="">
			<view class="tn-tag-content tn-margin tn-text-justify">
				<ad unit-id="adunit-65c56a85e788fe7b"></ad>
			</view>
		</view>
		<!-- 信息流广告结束 -->

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>

		<!-- 试卷排行开始-->
		<view class="tn-padding-top-sm tn-padding-bottom-sm" style="padding-bottom: 200rpx;">
			<view class="tn-margin">
				<view class="tn-flex tn-flex-row-between">
					<view class="justify-content-item tn-text-bold tn-text-xl">
						答题排行
					</view>
					<view class="justify-content-item tn-margin-right tn-text-df tn-color-gray">
						<text class="tn-padding-xs">该数据根据历史答题记录统计(含重复)</text>
					</view>
				</view>
			</view>
			<block v-for="(item, index) in rankList">
				<view class="">
					<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
						<view class="tn-flex tn-flex-col-center">
							<view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center" style="color: #7C8191;">
								<view class="" style="display: flex;align-items: center;">
									<text style="padding-right: 10rpx;">第{{ index + 1 }}名</text>
									<img :src="item.user.avatar_url" alt="" srcset=""
										style="width: 50rpx;height: 50rpx;border-radius: 50%;">
								</view>
							</view>
							<view class="tn-margin-left-sm tn-flex-1">{{item.user.nickname}}</view>
							<view class="tn-color-gray">{{item.score}}</view>
						</view>
					</tn-list-cell>
				</view>
			</block>
		</view>
		<!-- 试卷排行结束 -->

		<!-- 底部导航开始 -->
		<view id="top-info" class="tn-footerfixed tn-safe-area-inset-bottom tn-bg-white"
			:style="{transform: `translateY(${topInfoTranslateY}px)`}">
			<view class="tn-flex tn-flex-row-between tn-flex-col-center">
				<view class="tn-flex-2 justify-content-item tn-color-gray">
					<view class="tn-flex tn-flex-row-center">
						<view class="tn-flex-1" @click="tn('/pages/index/index', 1)">
							<view class="tn-icon-home-in" style="font-size: 42rpx;"></view>
							<view class="tn-text-center tn-text-sm tn-padding-top-xs">首页</view>
						</view>
						<view class="tn-flex-1 tn-padding-right-xl" @click="subscribe">
							<button class="tn-button--clear-style" style="border-radius: 0;">
								<view class="tn-icon-notice" style="font-size: 42rpx;"></view>
								<view class="tn-text-center tn-text-sm tn-padding-top-xs">订阅</view>
							</button>
						</view>
					</view>
				</view>
				<view class="tn-flex-3 justify-content-item tn-padding-top-sm tn-padding-bottom-sm">
					<tn-button shape="round" @click="previewQRCodeImage" backgroundColor="#27B93A"
						padding="38rpx 0" width="40%" :fontSize="30" shadow>
						<text class="tn-color-white" hover-class="tn-hover" :hover-stay-time="150">
							在线指导
						</text>
					</tn-button>
					<tn-button shape="round" @click="onlineExam(collectionContent.uid, 2)" backgroundColor="tn-main-gradient-blue"
						padding="38rpx 0" margin="0 0 0 30rpx" width="40%" :fontSize="30" shadow>
						<text class="tn-color-white" hover-class="tn-hover" :hover-stay-time="150">
							数据报表
						</text>
					</tn-button>
				</view>
			</view>
		</view>
		<!-- 底部导航结束 -->
	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import {
		getCollectionContent,
		getSubmitCollectionInfo,
		getSubmitRankList
	} from "@/utils/api/exam.js"
	import {
		checkUserLoginState
	} from "@/utils/api/user.js"
	export default {
		name: 'TemplateProduct',
		mixins: [template_page_mixin],
		data() {
			return {
				topInfo: {
					height: 0,
				},
				topInfoTranslateY: 0,
				prevScrollTop: 0,
				collectionUid: "",
				submit_uid: "",
				groupList: [], // 头像原生数据
				groupAvatarList: [], //头像组装数据
				collectionContent: {},
				submitInfo: {},
				rankList: [],
			}
		},
		onReady() {
			this.getTopInfoRect()
		},
		onPageScroll(e) {
			this.handlePageScroll(e.scrollTop)
		},
		onLoad(params) {
			this.collectionUid = params.collection_uid || ""
			this.submit_uid = params.uid || ""
			this.getCollectionContent()
			this.getSubmitCollectionInfo()
			this.getSubmitRankList()
			this.$t.mpShare = {
				share: false
			}
			if (!this.$t.mpShare.share) {
				uni.hideShareMenu()
			}
		},
		methods: {
			// 获取答题排行
			getSubmitRankList() {
				getSubmitRankList({
					collection_uid: this.collectionUid
				}).then(res => {
					if (res.code == 100) {
						this.rankList = res.data
						return
					}
					this.$func.showTotast(res.msg)
				})
			},
			// 获取试卷详情
			getCollectionContent() {
				uni.showLoading({
					title: "试题努力加载中",
					icon: "none"
				})
				getCollectionContent({
					uid: this.collectionUid
				}).then(res => {
					uni.hideLoading()
					if (res.code == 100) {
						this.collectionContent = res.data
						this.collectionContent.score = parseFloat(res.data.jude_score + res.data.option_score).toFixed(2)
						this.swiperList = [{
							url: res.data.url + res.data.path
						}]
						return
					}
					this.$func.showTotast(res.msg)
				})
			},
			// 获取答卷详情
			getSubmitCollectionInfo() {
				getSubmitCollectionInfo({
					submit_uid: this.submit_uid
				}).then(res => {
					if (res.code == 100) {
						this.submitInfo = res.data
						return
					}
					this.$func.showTotast(res.msg)
				})
			},
			onlineExam(uid, type) {
				checkUserLoginState().then(res => {
					if (res.code == 100) {
						if (type == 1) {
							this.tn("/subpages/help/list")
						} else {
							this.$func.showToast("待开发中")
							//this.tn("/subpages/exam/reading/list?uid=" + uid)
						}
					} else {
						this.$func.showToast("请先登录")
						this.tn("/subpages/user/login")
					}
				})

			},
			// 预览作者图片
			previewQRCodeImage() {
			 this.$func.previewQRCodeImage()
			},
			// 跳转
			tn(e, type = 0) {
				if (type == 1) {
					uni.switchTab({
						url: e
					})
				} else {
					uni.navigateTo({
						url: e,
					});
				}
			},
			// 微信订阅消息
			async subscribe() {
				let subscribeResult = await this.$func.templateSubscribe(getApp().globalData.examUpdateTemplateId)
				let code = subscribeResult.code || 0
				if (code == 100) {
					this.$func.showToast("订阅成功")
					return
				}
				this.$func.showToast("订阅失败")
			},
			// 获取顶部销售信息容器相关信息
			getTopInfoRect() {
				this._tGetRect('#top-info').then((res) => {
					if (!res) {
						setTimeout(() => {
							this.getTopInfoRect()
						}, 50)
						return
					}
					this.topInfo.height = res.height
				})
			},
			// 处理页面滚动事件
			handlePageScroll(scrollTop) {
				if (this.prevScrollTop > scrollTop) {
					// 内容下滑，即手指从下往上滚
					this.topInfoTranslateY = 0
				} else {
					// 内容上滑，即手指从上往下滚
					if (scrollTop > this.topInfo.height) {
						this.topInfoTranslateY = this.topInfo.height
					}
				}
				this.prevScrollTop = scrollTop
			},
		}
	}
</script>

<style lang="scss" scoped>
	.template-product {}

	.tn-tabbar-height {
		min-height: 20rpx;
		height: calc(40rpx + env(safe-area-inset-bottom) / 2);
	}

	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 间隔线 start*/
	.tn-strip-bottom-min {
		width: 100%;
		border-bottom: 1rpx solid #F8F9FB;
	}

	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}

	/* 间隔线 end*/
	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 46rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
			background-size: cover;
		}
	}

	/* 标题 end */


	/* 底部*/
	.tn-footerfixed {
		position: fixed;
		background-color: rgba(255, 255, 255, 0.5);
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
		bottom: 0;
		width: 100%;
		transition: all 0.25s ease-out;
		will-change: transform;
		z-index: 100;
	}

	/* 底部 start*/
	.footerfixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 999;
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
	}
</style>